package com.pagoda.nerp.web.util;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class JaxbObjectAndXmlUnit {

    public static <T> T xml2Object(String xmlStr,Class<T> tClass)
    {
        try{
            JAXBContext context = JAXBContext.newInstance(tClass);
            Unmarshaller unmarshaller = context.createUnmarshaller();

            T t = (T) unmarshaller.unmarshal(new StringReader(xmlStr));

            return t;

        }catch (JAXBException e)
        {
            e.printStackTrace();
            return null;
        }
    }
}
